package com.ruoyi.web.controller.applet;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.HospitalSubscribeOrder;
import com.ruoyi.system.domain.dto.HospitalSubscribeCreateOrderDto;
import com.ruoyi.system.domain.vo.HospitalSubscribeOrderVo;
import com.ruoyi.system.service.IHospitalSubscribeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/applet/order")
public class HospitalSubscribeOrderAppletController extends BaseController
{
    @Autowired
    private IHospitalSubscribeOrderService hospitalSubscribeOrderService;

    /**
     * 查询订单关联的所有信息
     * @response {@link HospitalSubscribeOrderVo}
     */
    @GetMapping("/getOrderAllInfo")
    public TableDataInfo list(HospitalSubscribeOrder hospitalSubscribeOrder)
    {
        startPage();
        hospitalSubscribeOrder.setUserId(SecurityUtils.getUserId());
        List<HospitalSubscribeOrderVo> list = hospitalSubscribeOrderService.getOrderAllInfo(hospitalSubscribeOrder);
        return getDataTable(list);
    }

    /**
     * 创建订单
     * @param dto
     * @return
     */
    @PostMapping(value = "/createOrder")
    public AjaxResult createOrder(@RequestBody HospitalSubscribeCreateOrderDto dto)
    {
        return success(hospitalSubscribeOrderService.createOrder(dto));
    }

    /**
     * 订单支付
     * @param map
     * @return
     */
    @PostMapping(value = "/orderPay")
    @Log(title = "微信支付", businessType = BusinessType.EXPORT)
    public AjaxResult orderPay(@RequestBody Map<String,String> map)
    {
        return success(hospitalSubscribeOrderService.orderPay(map));
    }

    /**
     * 根据订单预约体检时间
     * @param order
     * @return
     */
    @PostMapping(value = "/makeAnAppointment")
    public AjaxResult makeAnAppointment(@RequestBody HospitalSubscribeOrder order)
    {
        return success(hospitalSubscribeOrderService.makeAnAppointment(order));
    }

    /**
     * 根据订单修改预约体检时间
     * @param order
     * @return
     */
    @PostMapping(value = "/updateMakeAnAppointment")
    public AjaxResult updateMakeAnAppointment(@RequestBody HospitalSubscribeOrder order)
    {
        return success(hospitalSubscribeOrderService.updateMakeAnAppointment(order));
    }


    /**
     *根据订单id获取检查结果图片
     */
    @GetMapping("/getProjectPhotographByOrderId")
    public AjaxResult getProjectPhotographByOrderId(@RequestParam Long orderId)
    {
        return success(hospitalSubscribeOrderService.selectHospitalSubscribeOrderById(orderId));
    }

    /**
     *根据订单号获取检查结果图片
     */
    @GetMapping("/getProjectPhotographByOrderNo")
    public AjaxResult getProjectPhotographByOrderNo(@RequestParam String orderNo)
    {
        return success(hospitalSubscribeOrderService.getOrderInfoByOrderNo(orderNo));
    }
}
